/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package model.dao.loai;

import model.dao.AbstractQuery;
import model.entity.Loai;
import model.util.HibernateUtil;
import org.hibernate.HibernateException;
import org.hibernate.Session;

/**
 *
 * @author Admin
 */
public class LoaiDAO {
    private static String LOAD_1_Loai = "FROM Loai loai WHERE loai.loaiMa =";
    
    public static final int insertLoai(Loai loai){
        Session session = HibernateUtil.getSessionFactory().openSession();
        int id;
        try {
            session.beginTransaction();
            session.save(loai);
            session.getTransaction().commit();
            id = loai.getLoaiMa();
        } catch (HibernateException e) {
            session.getTransaction().rollback();
            throw new HibernateException(e);
        }finally{
            session.close();
        }
        return id;
        
    }
    public static  void deleteLoai(int giaMa){
        AbstractQuery.modifyObject(3, AbstractQuery.loadObject(LOAD_1_Loai + giaMa).get(0));
    }
}
